package com.thinkgem.jeesite.modules.sys.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.thinkgem.jeesite.common.service.BaseService;
import com.thinkgem.jeesite.modules.cms.entity.Site;
import com.thinkgem.jeesite.modules.cms.utils.CmsUtils;
import com.thinkgem.jeesite.modules.front.entity.FrontUser;
/**
 * 前台拦截器
 * @author ThinkGem
 * @version 2014-8-19
 */
public class FrontInterceptor extends BaseService implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		request.setAttribute("site", CmsUtils.getSite(Site.defaultSiteId()));
		request.setAttribute("frontUser", new FrontUser());
		
		String url = request.getRequestURI();
		if(url.contains("f/front-center_")){
			FrontUser frontUserInfo = (FrontUser)request.getSession().getAttribute("frontUserInfo");
			if(frontUserInfo == null){
				request.setAttribute("message", "请登陆");
				request.getRequestDispatcher("/WEB-INF/views/modules/cms/front/themes/wending/frontIndex.jsp").forward(request, response);
				return false;
			}
		}
		
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

}
